package manager.data;

import java.util.ArrayList;

import manager.analysis.DataAnalysis;
import manager.event.EventObject;
import manager.logdata.LazyPersistedLogData;
import manager.utility.PacketParser;

public class EventsManager {
	private LazyPersistedQueue lpq;
	private static LazyPersistedLogData lpld;
	private static ArrayList<RawDataObject> memoryLog;
	private static DataAnalysis da;
	private static EventObject eo;
	
	public EventsManager() {
		da= new DataAnalysis();
		memoryLog = new ArrayList<RawDataObject>();
		lpld= new LazyPersistedLogData(memoryLog);
		lpld.start();
		eo= new EventObject();
	}

	public void setQueue(LazyPersistedQueue lpq){
		this.lpq=lpq;
	}
	
	public void processEvents() {
		int size=lpq.memorySize();
		for(int i=0;i<size;i++){
			RawDataObject rdo = lpq.pop();
			PacketParser pp = PacketParser.getInstance();
			if(pp.parse(rdo)){
				memoryLog.add(rdo);
				synchronized(lpld){
					lpld.notify();
				}
				if(da.isValid(rdo))
					eo.insertBlock(rdo);
				
				lpq.dequeue();
			}
		}
		
	}
	


}
